<?php
/**
 * Login form.
 * 
 * @package disputeo
 * @version 1.0
 * @author jimmy.dixon
 */

class Application_Form_Login extends Application_Form_Entry
{
    /**
     * @var string 
     */
    protected $_legend = 'Already got a disputeo account?';
    
    /**
     * @var string 
     */
    protected $_notFound = 'No account found for this user name and password.';

    /**
     * Add form elements
     */
    public function init()
    {
        $this->setName('login');
        $this->setAction('/login/login');
        $this->_addUserNameElement();
        $this->_addPasswordElement();
        $this->_addRememberElement();
        $this->_setDisplayGroup();
        $this->_addDisplayGroup('loginGroup', $this->_legend);
        $this->_addSubmitElement('Login');
    }

    /**
     * Set error messages on username and password
     */
    public function addNotFoundError()
    {
        $this->getElement('password')->addError($this->_notFound);
        $this->getElement('username')->addError(null);
    }

    /**
     * Add remember me element
     */
    protected function _addRememberElement()
    {
        $remember = new Zend_Form_Element_Checkbox('remember');
        $remember->setChecked(true)
            ->setDecorators(array(
                array('ViewHelper'),
                array('Callback',
                    array('callback' =>
                        array('Application_Form_Login', 'checkboxLabel')))));
        $this->addElement($remember);
    }

    /**
     * Set fieldset
     */
    protected function _setDisplayGroup()
    {
        $this->_displayGroup = array(
            'username',
            'password',
            'remember'
        );
    }

    /**
     * Get checkbox label HTML
     * @return string
     */
    public static function checkboxLabel($content, $element, array $options)
    {
        return '<label for="remember">Remember Me</label>';
    }

}

?>